<template>
  <div class="search">
    <f-form ref="form" :action="api.consumption" :form-key="this.formItem.consumptionId" :file-ids="fileIds">
      <f-form-item label="收款单位" name="receivingUnit" required :value="formItem.receivingUnit"/>
      <f-form-item label="部门" type="select" name="deptId"  :showSearch="true" :data="api.dept.list" label-key="deptName" value-key="deptId" :value="formItem.deptId"/>
      <f-form-item label="申请金额" type='number' dataType='number'  name="applyAmount" required :value="formItem.applyAmount"/>
      <f-form-item label="款项类型" name="paymentTypeId" required type="select" :data="api.paymentType.list" label-key="paymentTypeName" value-key="paymentTypeId"  :value="formItem.paymentTypeId" :showSearch="true"/>
      <f-form-item label="开户行" name="bank" required :value="formItem.bank"/>
      <f-form-item label="银行账号" name="bankNo" required :value="formItem.bankNo"/>
      <f-form-item label="备注" name="remark" :value="formItem.remark"/>
      <f-form-item label="附件" type="upload" name="rcImage" :value="formItem.rcImage" value-type="json" :file-max="50" @uploadSuccess="uploadSuccess"/>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'consumptionForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        fileIds: [],//上传文件ID
        loaded: false,//是否加载完成
        formItem: this.getFormItem(),
        paymentTypeData: [
          { label: '采购预付款', value: 1 },
          { label: '快递费', value: 2 },
          { label: '销售费用', value: 3 },
          { label: '市场保证金', value: 4 },
          { label: '其他', value: 5 },
          { label: '开票税金', value: 6 }
        ]
      }
    },
    methods: {
      getFormItem() {
        return {
          consumptionId: '',
          deptId: null,
          consumptionNo: '',
          checkState:0,
          receivingUnit: '',
          applyAmount: 0,
          paymentTypeId: '',
          bank: '',
          bankNo: '',
          attachmentImage: '',
          applyUserId: '',
          payUserId: '',
          payDate: '',
          createTime: '',
          updateTime: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.consumptionId) {
          let params = {
            consumptionId: data.consumptionId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //文件上传回调
      uploadSuccess(fileUrl, files, fileIds) {
        this.fileIds = fileIds
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({processInstanceId:this.formItem.processInstanceId}, callback)
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
